//
//  mainViewController.m
//  diantai
//
//  Created by 吕斌利 on 2019/8/25.
//  Copyright © 2019 吕斌利. All rights reserved.
//

#import "mainViewController.h"
#import "JXPagerView.h"
#import "JXCategoryView.h"
#import "oneViewController.h"
#import "threeViewController.h"
#import "twoViewController.h"
#import "worldViewController.h"
#import "networrkViewController.h"
static const CGFloat JXheightForHeaderInSection = 50;
@interface mainViewController ()<JXPagerViewDelegate, JXCategoryViewDelegate>
@property (nonatomic, strong) JXPagerView *pagingView;
@property (nonatomic, strong) JXCategoryTitleView *categoryView;

@property (nonatomic, strong) NSArray <NSString *> *titles; ///<标题数组

@property (nonatomic, strong) NSArray *listViewArray; ///<子控制器数组

@end

@implementation mainViewController

#pragma mark - LifeCicle
- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    self.pagingView.frame = CGRectMake(0, kNavBarHeight+55, kScreenWidth, kScreenHeight-kNavBarHeight-50);
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColorFromHex(0xF0F0F0);
    self.navigationView.titleLabel.text = @"菜单";
    [self blockMethod];
    [self settingNavigationView];
    [self creatUI];
}
//初始化
- (void)setupViews {
    
}
//约束
- (void)setupLayout {
    
}
#pragma mark - Block(Block回调)

- (void)blockMethod {
//    WeakSelf
  
}

#pragma mark 设置导航栏
- (void)settingNavigationView {
//    [self.navigationView setTitle:@"我的预约"];
}
- (void)creatUI {
    _titles = @[@"推荐", @"国家电台", @"省电台",  @"Network"];
    oneViewController * StationInfoVC = [oneViewController new];
    [self addChildViewController:StationInfoVC];
    WeakSelf
    StationInfoVC.delegetBlock = ^(NSArray * _Nonnull data, NSInteger inx) {
        StrongSelf
        if (self.delegetBlock) {
            self.delegetBlock(data, inx);
        }
    };

    twoViewController* PileList = [twoViewController new];
    [self addChildViewController:PileList];

    PileList.delegetBlock = ^(NSArray * _Nonnull data, NSInteger inx) {
        StrongSelf
        if (self.delegetBlock) {
            self.delegetBlock(data, inx);
        }
    };
    threeViewController * UserComment = [threeViewController new];
    [self addChildViewController:UserComment];
    UserComment.delegetBlock = ^(NSArray * _Nonnull data, NSInteger inx) {
        StrongSelf
        if (self.delegetBlock) {
            self.delegetBlock(data, inx);
        }
    };
     networrkViewController * UserComment3 = [networrkViewController new];
    [self addChildViewController:UserComment3];
    UserComment3.delegetBlock = ^(NSArray * _Nonnull data, NSInteger inx) {
        StrongSelf
        if (self.delegetBlock) {
            self.delegetBlock(data, inx);
        }
    };
    _listViewArray = @[StationInfoVC,PileList,UserComment,UserComment3];
    
    _categoryView = [[JXCategoryTitleView alloc] initWithFrame:CGRectMake(0, kNavBarHeight, [UIScreen mainScreen].bounds.size.width, 50)];
    self.categoryView.titles = self.titles;
    self.categoryView.backgroundColor = [UIColor whiteColor];
    self.categoryView.delegate = self;
    self.categoryView.titleSelectedColor = UIColorFromHex(0x01CA9E);
    self.categoryView.titleColor = UIColorFromHex(0x3C3C3C);
    self.categoryView.titleColorGradientEnabled = YES;
    self.categoryView.titleLabelZoomEnabled = NO;
    [self.view addSubview:self.categoryView];
    
    JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
    lineView.indicatorColor = UIColorFromHex(0x00ca9d);
    lineView.indicatorWidth = 30;
    lineView.indicatorHeight = 1;
    self.categoryView.indicators = @[lineView];
    
    _pagingView = [[JXPagerView alloc] initWithDelegate:self];
    _pagingView.pinSectionHeaderVerticalOffset = 0;
    [self.view addSubview:self.pagingView];
    if (@available(iOS 11.0, *)) {
        _pagingView.mainTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else{
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.categoryView.contentScrollView = self.pagingView.listContainerView.collectionView;
    self.navigationController.interactivePopGestureRecognizer.enabled = (self.categoryView.selectedIndex == 0);
}
#pragma mark - JXPagingViewDelegate

- (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
    return NULL;
}

- (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
    return 0;
}

- (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return 0;
}

- (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
    return NULL;
}
- (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView{
    return self.listViewArray.count;
}

- (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index{
    return self.listViewArray[index];
}


- (void)mainTableViewDidScroll:(UIScrollView *)scrollView {
    
    
}

- (void)mainTableViewCell:(UITableViewCell *)cell containerView:(UIView *)containerView {
    
}

#pragma mark - JXCategoryViewDelegate

- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
}

@end
